package com.ethink.order.common.properties;

import com.baomidou.mybatisplus.core.enums.SqlMethod;
import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

/**
 * @author default
 * @version 1.0.0
 * @ClassName DelById.java
 * @Description
 * @createTime 2022年12月09日 14:21:00
 */
public class DelById extends AbstractMethod {
    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
        String sqlSet = "SET is_deleted = 1 ";
        String sqlMethod = "delById";
        String sql = String.format(SqlMethod.LOGIC_DELETE_BY_ID.getSql(), tableInfo.getTableName(), sqlSet,
                tableInfo.getKeyColumn(), tableInfo.getKeyProperty(),
                tableInfo.getLogicDeleteSql(true, true));
        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
        return this.addUpdateMappedStatement(mapperClass, modelClass, sqlMethod, sqlSource);
    }
}
